package com.gl.order.controller;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.json.JSONUtil;
import com.gl.order.commom.ResultBean;
import com.gl.order.entity.AreaDict;
import com.gl.order.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: liangSY
 * @Date: 2021/6/24 14:23
 * @ClassName: AreaController
 */
@Api(tags = "地区")
@RestController
@RequestMapping("/areas")
public class AreaController {

    private AreaService areaService;

    public AreaController(AreaService areaService) {
        this.areaService = areaService;
    }

    @GetMapping
    @ApiOperation("获取所有地区列表数据，three结构")
    public ResultBean<List<Tree<Integer>>> getAreaThree(){
        return ResultBean.success(areaService.getAreaToThree());
    }

    @GetMapping("/parent/{pid}")
    @ApiOperation("根据估计父级id获取其下的子数据，例如，输入省的编号获取其下面的所有城市")
    @ApiImplicitParam(name = "pid",value = "pid",dataType = "Integer",paramType = "path")
    public ResultBean<List<Tree<Integer>>> findById(@PathVariable("pid") String pid){
        return ResultBean.success(areaService.getAreaByPid(pid));
    }

    @GetMapping("/province")
    @ApiOperation("获取所有省")
    public ResultBean<List<Tree<Integer>>> listOfProvince(){
        return ResultBean.success(areaService.getAreaByLv(1));
    }


}
